package controller.view;

import java.util.ArrayList;
import java.util.List;

import view.interfaces.Selectable;

public class SelectionHandler {
	private List<Selectable> selectables = new ArrayList<Selectable>();

	public SelectionHandler() {
	}

	public void setSelected(Selectable selectable) {
		unselectAll();
		addSelected(selectable);
	}

	public void addSelected(Selectable selectable) {
		if (!selectables.contains(selectable)) {
			selectables.add(selectable);
			selectable.select();
		}
	}

	public void unselectAll() {
		for (Selectable s : selectables) {
			s.unselect();
		}
		selectables.clear();
	}

	public boolean isSelected(Selectable selectable) {
		return selectables.contains(selectable);
	}
}
